import os
import shutil
import pytest

if __name__ == '__main__':
    def clear_directory(directory_path):
        # 遍历目录下的所有文件和子目录
        for filename in os.listdir(directory_path):
            file_path = os.path.join(directory_path, filename)
            try:
                if os.path.isfile(file_path) or os.path.islink(file_path):
                    # 删除文件或符号链接
                    os.unlink(file_path)
                elif os.path.isdir(file_path):
                    # 删除目录及其内容
                    shutil.rmtree(file_path)
            except Exception as e:
                print(f'Failed to delete {file_path}. Reason: {e}')
    # 使用函数
    clear_directory(r'F:\Playwright_Project_POM\temp')
    clear_directory(r'F:\Playwright_Project_POM\test-results')

    pytest.main(['-vs','--alluredir=./temp'])
    os.system('allure generate ./temp -o ./reports --clean')
